#include "logoscene.h"
#include "common.h"
#include "startscene.h"
#include "loadscene.h"

namespace fireplane
{
	CCScene* LogoScene::scene()
	{
		CCScene * scene = NULL;
		do 
		{
			// 'scene' is an autorelease object
			scene = CCScene::create();
			CC_BREAK_IF(! scene);

			CCNode* parentNode = Common::createScaleNode(scene);
			// 'layer' is an autorelease object
			LogoScene *layer = LogoScene::node();
			CC_BREAK_IF(! layer);

			// add layer as a child to scene
			parentNode->addChild(layer);
		} while (0);

		// return the scene
		return scene;
	}

	bool LogoScene::init()
	{
		CCSprite* sprite = CCSprite::create("logo/logo.jpg");
		CCSize size = Common::getWinSize();

		sprite->setPosition(ccp(size.width / 2,size.height / 2));
		addChild(sprite);
		sprite->setOpacity(0);
		sprite->runAction(
			CCSequence::create(
				CCFadeIn::create(1.0f),
				CCDelayTime::create(1.0f),
				CCFadeOut::create(1.0f),
				CCCallFunc::create(this,callfunc_selector(LogoScene::onEnd)),
				NULL
				));

		return true;
	}

	void LogoScene::onEnd()
	{
		LoadingScene::registerLoadFunction(&(StartScene::loadRes));
		CCScene *pScene = LoadingScene::scene();
		CCDirector::sharedDirector()->replaceScene(pScene);
	}

};